<template>
  <div class="login">
    <div class="login-box">
      <h1>后台管理系统</h1>
      <div class="login-area">
        <div class="login-method">
          <div @click="numberLogin" :class="{ 'is-number-login': active }">
            <el-icon><User /></el-icon>
            账号登录
          </div>
          <div @click="phoneLogin" :class="{ 'is-phone-login': !active }">
            <el-icon><Cellphone /></el-icon>
            手机登录
          </div>
        </div>
        <div class="login-form">
          <number-logn v-if="active" ref="numberLoginRef"></number-logn>
          <phone-login v-else></phone-login>
        </div>
        <div class="login-btn">
          <el-button size="large" type="info" @click="login">登录</el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from "vue";

import NumberLogn from "./cpns/number-login.vue";
import PhoneLogin from "./cpns/phone-login.vue";

export default defineComponent({
  components: {
    NumberLogn,
    PhoneLogin
  },
  setup() {
    const active = ref(true);
    const numberLogin = () => {
      active.value = true;
    };
    const phoneLogin = () => {
      active.value = false;
    };
    // 登录
    const numberLoginRef = ref<InstanceType<typeof NumberLogn>>();
    const login = () => {
      if (active.value) {
        numberLoginRef.value?.numberLoginMethod();
      } else {
        console.log("手机登录");
      }
    };
    return { numberLogin, phoneLogin, active, login, numberLoginRef };
  }
});
</script>

<style lang="less" scoped>
.login {
  height: 100%;
  width: 100%;
  background-image: url("../../assets/img/login-background1.jpg");
  background-position: center;
  background-size: cover;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  .login-box {
    margin-bottom: 130px;
    h1 {
      width: 450px;
      margin: 0 0 10px 50%;
      transform: translate(-50%);
      text-align: center;
    }
    .login-area {
      width: 450px;
      // height: 300px;
      background-color: #fff;
      border-radius: 10px;
      display: flex;
      flex-direction: column;
      .login-method {
        display: flex;
        flex-direction: row;
        justify-content: center;
        div {
          width: 50%;
          height: 40px;
          line-height: 40px;
          text-align: center;
          color: #615656;
          font-size: 16px;
        }
        div:hover {
          background-color: #eee;
          cursor: pointer;
          color: #67c23a;
        }
        div:nth-child(1) {
          border-top-left-radius: 10px;
        }
        div:nth-child(2) {
          border-top-right-radius: 10px;
        }
        .is-number-login {
          color: #67c23a !important;
        }
        .is-phone-login {
          color: #67c23a !important;
        }
      }
      .login-btn {
        box-sizing: border-box;
        width: 100%;
        padding: 20px 30px;
        display: flex;
      }
    }
  }
}
.el-icon {
  top: 3px;
}
.el-button {
  flex: 1;
}
</style>
